package main

import (
	"log"
	"net"
	"sync"
	"time"
)

func main()  {
	listen,e := net.Listen("tcp","127.0.0.1:8890")
	if nil != e{
		log.Print(e.Error())
	}
	wg := sync.WaitGroup{}
	wg.Add(1)
	go func() {
		wg.Done()

		sock,e := listen.Accept()

		if nil != e{
			log.Print(e.Error())
		}

		buf := make([]byte,3)
		n,e := sock.Read(buf)
		if nil != e{
			log.Print(e.Error())
		}
		log.Print(n,buf)
	}()
	go func() {
		wg.Wait()
		tcpAddr,e := net.ResolveTCPAddr("tcp","127.0.0.1:8890")
		if nil != e{
			log.Print(e.Error())
		}
		cnn,e :=net.DialTCP("tcp",nil,tcpAddr)
		if nil != e{
			log.Print(e.Error())
			return
		}
		_,e = cnn.Write([]byte{1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,20})
		log.Print("sended")
	}()
	for true {
		time.Sleep(time.Second)
	}
}